/**
 * 
 */

var fisrtonload=0;
var gotoicon = new actionBase();

gotoicon.randerlayer =LAYER_BG_0;

/*
for (var i=1;i<7;i++){
	gotoicon.animimgs[i-1] = new Image();
	gotoicon.animimgs[i-1].src ="/RPG/sucai/ui/ic" + i + ".png";
}*/
createAnima(gotoicon.animimgs,"/RPG/sucai/ui/ic",".png",6,false);
gotoicon.autoreplay = true;
gotoicon.stepcnt =6;
gotoicon.intval =3;

function setGotoIcon(x,y){
	gotoicon.x = x*WALKSTEPD*WALKSTEPCNT+5;
	gotoicon.y = (y+1)*WALKSTEPD*WALKSTEPCNT-20;
}

//null for preload
function createAnima(imglst,path,ex,cnt,isreload){
	for (var i=1 ;i<=cnt;i++){
		var newimg =  new Image();
		newimg.src =path + i+ ex;
		if (imglst!=null) {
			imglst[i-1] = newimg ;
		}
		if (isreload) PreLoadlst.push(newimg );//FIX
	}
}


//人物对话框
/*
 * #u01 背景
 * #u02 文字框
 * #u03 头像
 * */
function ShowTDialog(text,imgurl){
	//TODO 日后可以删掉 bEatmsg
	bEatmsg = true;
	$("#u02").html(text);
	if (imgurl!=null) $("#u03").attr("src",imgurl);

	$("#u02").fadeIn();
	if (imgurl!=null) $("#u03").fadeIn();
	$("#u01").fadeIn();
	
	if (fisrtonload ==1) return;//这里没有搞清楚，如果第二次还用offset会错位
	
	//$("#u01").addClass("ui-dialog_0");
	var y=$("#gscreen").offset().top + $("#gscreen").height() - $("#u01").height();
	var x=$("#gscreen").offset().left;  
	$("#u01").width($("#gscreen").width()-15);
	$("#u02").width(($("#gscreen").width()-200));
	$("#u01").offset({top:y,left:x});
	
	y=$("#gscreen").offset().top + $("#gscreen").height() - HEADER_W;
	x=$("#gscreen").offset().left +  $("#gscreen").width() - HEADER_H;  
	$("#u03").offset({top:y,left:x});
	
	document.getElementById('u01').onmouseup =TDialogEvent;
	//document.getElementById('u02').onmouseup =TDialogEvent;
	document.getElementById('u03').onmouseup =TDialogEvent;
	fisrtonload =1;
}

TDialogEvent =function (){
	var scrollt = $("#u02").scrollTop();

	if (scrollt + 80 < $("#u02").attr("scrollHeight") ){
		//$("#u02").scrollTop(scrollt+80);
		$("#u02").animate({scrollTop: scrollt+74});
	} else {
		bEatmsg = false;
		$("#u02").hide();
		$("#u03").hide();
		$("#u01").hide();
	
		GoNextSnario();

	}
}
//Fight Ui
function setupUI() {
	$("#dlg1t1").hover(
			function(){$(this).attr("src","/RPG/sucai/ui/21.png");},
			function(){$(this).attr("src","/RPG/sucai/ui/11.gif");}
	);
	$("#dlg1t2").hover(
			function(){$(this).attr("src","/RPG/sucai/ui/22.png");},
			function(){$(this).attr("src","/RPG/sucai/ui/12.gif");}
	);
	$("#dlg1t3").hover(
			function(){$(this).attr("src","/RPG/sucai/ui/23.png");},
			function(){$(this).attr("src","/RPG/sucai/ui/13.gif");}
	);
	$("#dlg1t4").hover(
			function(){$(this).attr("src","/RPG/sucai/ui/24.png");},
			function(){$(this).attr("src","/RPG/sucai/ui/14.gif");}
	);
	
	
	$("#dlg1t1").click ( 
		function (){
		UnShowFMenu();
		AcceptSprite.attact();
		}
	);
	$("#dlg1t2").click ( 
			function (){
				alert("尚未实装");
		
			}
		);
	$("#dlg1t3").click ( 
			function (){
				alert("尚未实装");
			
			}
		);
	$("#dlg1t4").click ( 
			function (){
				alert("尚未实装");
			
			}
		);
}
function showFMenu(){
	$("#dlg1t1").fadeIn();$("#dlg1t2").fadeIn();
	$("#dlg1t3").fadeIn();$("#dlg1t4").fadeIn();
	$("#dlg1").fadeIn();
}
function UnShowFMenu(){
	$("#dlg1t1").fadeOut();$("#dlg1t2").fadeOut();
	$("#dlg1t3").fadeOut();$("#dlg1t4").fadeOut();
	$("#dlg1").fadeOut();
}
//更新战斗时的状态
function updateFState(){
	var hpv=AcceptSprite.properties.get("hp");
	var qv=AcceptSprite.properties.get("q");
	$("#HPval").html(hpv);
	$("#Qval").html(qv);
	
	var hp_p =hpv/AcceptSprite.GetPro("maxHp")*48;
	var q_p =qv/AcceptSprite.GetPro("maxQ")*48;
	
	$("#HPbar").width(hp_p);
	$("#Qbar").width(q_p);
}
//战斗时候对话框
function showFDlg(str){
	$("#dlg1").fadeIn();
	$("#f_dlgtxt").fadeIn();
	$("#f_dlgtxt").html(str);
}

//禁止混淆 Begin
//window['ShowTDialog'] = ShowTDialog; 
//禁止混淆 END
